package com.tengju.payment.domain.service.transfer;

import com.tengju.payment.domain.model.ChannelType;
import com.tengju.payment.domain.shard.DomainException;
import com.tengju.payment.domain.shard.DomainExceptionCode;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 通用策略选择器
 */
@Service
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class TransferStrategyChooser {

    private final AbstractTransferService citicTransferService;
    private final AbstractTransferService unionPayTransferService;
    private final AbstractTransferService pingAnTransferTransferService;

    /**
     * 根据渠道类型+业务类型确定转账策略
     */
    public AbstractTransferService chooseTransferStrategy(ChannelType channelType) {
        if (ChannelType.CITIC_BANK == channelType) {
            return citicTransferService;
        } else if (ChannelType.UNION_PAY == channelType) {
            return unionPayTransferService;
        } else if (ChannelType.PING_AN_DEPOSITORY == channelType) {
            return pingAnTransferTransferService;
        }
        throw DomainException.error(DomainExceptionCode.TRANSFER_STRATEGY_NOT_FOUND, channelType.name());
    }

}
